package com.zboot.zbootadmin.common.utils;

import java.lang.reflect.Method;

/**
 * @Author: zyt
 * @Description:反射工具类
 * @Date: Created in 15:42 2020/4/5
 */
public class ReflectionUtils {

    public static String getSetMethod(String string) {
        char[] cs=string.toCharArray();
        cs[0]-=32;
        //string.substring(0,1).toUpperCase()+string.substring(1)
        return  "set"+String.valueOf(cs);
    }
    public static String getGetMethod(String string) {
        char[] cs=string.toCharArray();
        cs[0]-=32;
        return  "get"+String.valueOf(cs);
    }

    public static <T>void setValue(Class<?> clazz,T t,String methods,Object value) throws Exception {
        Method method = clazz.getDeclaredMethod(methods,String.class);
        method.setAccessible(true);
        method.invoke(t,value);
    }

    public static <T> Object getValue(Class<?> clazz,T t,String methods) throws Exception {
        Method method = clazz.getDeclaredMethod(methods);
        /*method.setAccessible(true);*/
        return method.invoke(t);
    }
}
